package view
{
	
	import data.AppConfig;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * 可视化节点 
	 * @author Administrator
	 * 
	 */	
	public class NodeCircle extends Sprite
	{
		private var cavas:Shape;
		private var nodeLabel:TextField;
		
		public function NodeCircle(key:int,color:int)
		{
			cavas = new Shape();
			this.addChild(cavas);
			cavas.graphics.lineStyle(1);
			cavas.graphics.beginFill(getColor(color));
			cavas.graphics.drawCircle(0,0,10);
			cavas.graphics.endFill();
			
			nodeLabel = new TextField();
			nodeLabel.x = -8;
			nodeLabel.y = -8;
			nodeLabel.text = key.toString();
			nodeLabel.textColor = 0xffffff;
			this.addChild(nodeLabel);
			
			this.buttonMode = true;
			this.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
		}
		
		/**
		 * 返回节点的颜色 
		 * @param color
		 * @return 
		 * 
		 */		
		private function getColor(color:int):uint
		{
			if(color == AppConfig.BLACK)
				return 0x000000;
			else
				return 0xff0000;
		}
	
		
		public function setNodeLable(name:String):void
		{
			this.nodeLabel.text = name;
		}
		
		private function onMouseDown(evt:MouseEvent):void
		{
			this.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
			this.startDrag(true);
		}
		
		private function onMouseUp(evt:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_UP,onMouseUp);
			this.stopDrag();
		}
		
	}
}